const http = require('http');
const fs = require('fs');
const path = require('path');

const server = http.createServer();
server.on('request', (req, res) => {
    // res.setHeader('Content-Type', 'text/html; charset=utf-8');
    const url = path.join(__dirname, req.url);
    fs.readFile(url, 'utf8', (err, data) => {
        if (err) {
            return res.end('出错了');
        }
        console.log(url);
        res.end(data);
    });
});
server.listen(80, () => {
    console.log('启动成功')
});
